﻿//------------------------------------------------------------------------------
// ╭─────────────────────────────╮
// │ ╭─╮     ╭─╮              TM │   ╠═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╣
// │ │ │     │ │                 │                                           ☺  
// │ │ ╰───╮ │ │ ╭─────╮ ╭─────╮ │     Name:Wedn.Net 模版引擎类        ♮ ♪ ♩
// │ │ ╭─╮ │ │ │ │ ╭─╮ │ │ ╭─╮ │ │                                    ♫ ♭      
// │ │ ╰─╯ │ │ │ │ ╰─╯ │ │ ╰─╯ │ │     Author:iceStone               ♬ ♪       
// │ └─────╯ └─╯ ╰─────╯ ╰───╮ │ │     Chinese:汪磊                              
// │                     ┌───╯ │ │                                              
// │                     ╰─────╯ │   ╠═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╬═╣
// ╰─────────────────────────────╯                                              
//------------------------------------------------------------------------------
using System.Collections.Generic;
using System.Web.Mvc;
using Wedn.Net.Common;

namespace Wedn.Net.TEngine
{
    /// <summary>
    /// 模版引擎类
    /// </summary>
    public class FrontViewEngine : BuildManagerViewEngine
    {
        /// <summary>
        /// 模版引擎构造
        /// </summary>
        public FrontViewEngine() : this(null) { }

        /// <summary>
        /// 模版引擎构造
        /// </summary>
        public FrontViewEngine(IViewPageActivator viewPageActivator)
            : base(viewPageActivator)
        {
            AreaViewLocationFormats = new[] { "~/Areas/{2}/Views/{1}/{0}.cshtml", "~/Areas/{2}/Views/{1}/{0}.vbhtml", "~/Areas/{2}/Views/Shared/{0}.cshtml", "~/Areas/{2}/Views/Shared/{0}.vbhtml" };
            AreaMasterLocationFormats = new[] { "~/Areas/{2}/Views/{1}/{0}.cshtml", "~/Areas/{2}/Views/{1}/{0}.vbhtml", "~/Areas/{2}/Views/Shared/{0}.cshtml", "~/Areas/{2}/Views/Shared/{0}.vbhtml" };
            AreaPartialViewLocationFormats = new[] { "~/Areas/{2}/Views/{1}/{0}.cshtml", "~/Areas/{2}/Views/{1}/{0}.vbhtml", "~/Areas/{2}/Views/Shared/{0}.cshtml", "~/Areas/{2}/Views/Shared/{0}.vbhtml" };
            ViewLocationFormats = new[] { Config.ThemeRoot + Setting.Theme + "/Views/{0}.cshtml", Config.ThemeRoot + Setting.Theme + "/Views/{0}.vbhtml", Config.ThemeRoot + Setting.Theme + "/Views/{1}/{0}.cshtml", Config.ThemeRoot + Setting.Theme + "/Views/{1}/{0}.vbhtml", Config.ThemeRoot + Setting.Theme + "/Views/Shared/{0}.cshtml", Config.ThemeRoot + Setting.Theme + "/Views/Shared/{0}.vbhtml" };
            MasterLocationFormats = new[] { Config.ThemeRoot + Setting.Theme + "/Views/{0}.cshtml", Config.ThemeRoot + Setting.Theme + "/Views/{0}.vbhtml", Config.ThemeRoot + Setting.Theme + "/Views/{1}/{0}.cshtml", Config.ThemeRoot + Setting.Theme + "/Views/{1}/{0}.vbhtml", Config.ThemeRoot + Setting.Theme + "/Views/Shared/{0}.cshtml", Config.ThemeRoot + Setting.Theme + "/Views/Shared/{0}.vbhtml" };
            PartialViewLocationFormats = new[] { Config.ThemeRoot + Setting.Theme + "/Views/{0}.cshtml", Config.ThemeRoot + Setting.Theme + "/Views/{0}.vbhtml", Config.ThemeRoot + Setting.Theme + "/Views/{1}/{0}.cshtml", Config.ThemeRoot + Setting.Theme + "/Views/{1}/{0}.vbhtml", Config.ThemeRoot + Setting.Theme + "/Views/Shared/{0}.cshtml", Config.ThemeRoot + Setting.Theme + "/Views/Shared/{0}.vbhtml" };
            FileExtensions = new[] { "cshtml", "vbhtml" };
        }
        /// <summary>
        /// 创建局部视图
        /// </summary>
        /// <param name="controllerContext"></param>
        /// <param name="partialPath"></param>
        /// <returns></returns>
        protected override IView CreatePartialView(ControllerContext controllerContext, string partialPath)
        {
            IEnumerable<string> fileExtensions = FileExtensions;
            return new RazorView(controllerContext, partialPath, null, false, fileExtensions, base.ViewPageActivator);
        }
        /// <summary>
        /// 创建视图
        /// </summary>
        /// <param name="controllerContext"></param>
        /// <param name="viewPath"></param>
        /// <param name="masterPath"></param>
        /// <returns></returns>
        protected override IView CreateView(ControllerContext controllerContext, string viewPath, string masterPath)
        {
            string layoutPath = masterPath;
            IEnumerable<string> fileExtensions = FileExtensions;
            return new RazorView(controllerContext, viewPath, layoutPath, true, fileExtensions, base.ViewPageActivator);
        }
        
    }
}
